<template>
	<div>
		<div class="m-tabct" data-reactid="38">
			<div class="tabctitem">
				<div class="m-hmhot">
					<div class="hotop">
						<div class="hotopct">
							<div class="u-hmsprt hoticon"></div>
							<div class="hottime">
								<!-- react-text: 717 -->更新日期：
								<!-- /react-text -->
								<!-- react-text: 718 -->{{timestampToTime(time.trackNumberUpdateTime)}}
								<!-- /react-text -->
							</div>
						</div>
					</div>
					<div class="hotcont">
						<div class="m-sglst">
							<a to="/song" class="m-sgitem" v-for="(item,index) in list" @click="handleClick(index)">
								<div class="sgfl" v-if="index < 9" :class="{cred:index<3}">0{{index+1}}</div>
								<div class="sgfl" v-else>{{index+1}}</div>
								<div class="sgfr f-bd f-bd-btm">
									<div class="sgchfl">
										<div class="f-thide sgtl">
											{{item.name}}
											<span class="sgalia" v-if="item.alia[0]">
											({{item.alia[0]}})</span>
										</div>
										<div class="f-thide sginfo">
											<i class="u-hmsprt sghot"></i>
											<span v-for="(nm,index) in item.ar">
												{{nm.name}} <span v-if="index == 0 && item.ar.length == 2">/</span>
											</span>
											-
											<span>{{item.al.name}}</span>
										</div>
									</div>
									<div class="sgchfr">
										<span class="u-hmsprt sgchply"></span>
									</div>
								</div>
							</a>
						</div>
					</div>
					<div class="hotdn"><span class="hotview" @click="more()">查看完整榜单</span></div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import api from '.././api/index.js'
	export default {
		mounted() {
			// 做AJAX请求
			this._initData()
			this.$store.commit("setHidhd", {
				hidhd: false
			})
		},
		data() {
			return {
				list: [],
				time: ""
			}
		},
		methods: {
			_initData() {
				return new Promise((resolve, reject) => {
					var xhr = new XMLHttpRequest();
					xhr.open("GET", api.detail);
					xhr.send();
					xhr.addEventListener("readystatechange", function() {
						if(xhr.readyState == 4) {
							if(xhr.status == 200) {
								resolve(xhr.response);
							}
						}
					})
				}).then((res) => {
					this.list = JSON.parse(res).playlist.tracks
					this.time = JSON.parse(res).playlist
					this.list = this.list.slice(0, 20)
				})
			},
			handleClick(index) {
				this.$store.commit("setHidhd", {
					hidhd: true
				})
				let id = this.list[index].id
				this.$router.push({
					path: `/song/${id}`
				})
			},
			timestampToTime(timestamp) {
				var date = new Date(timestamp);
				var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
				var D = date.getDate() + '日';
				return M + D;
			},
			more() {
				alert("该功能暂未开放，敬请期待~~")
			}
		}
	}
</script>

<style scoped>
	.m-tabarea .m-tabct,
	.m-tabct .tabctitem {
		width: 100%;
		height: 100%;
	}
	
	.m-tabarea .m-tabct {
		display: block;
	}
	
	.m-hmhot .hotop {
		position: relative;
		padding-top: 38.9%;
		overflow: hidden;
		background: url(//s3.music.126.net/m/s/img/hot_music_bg_2x.jpg?f01a252…) no-repeat;
		background-size: contain;
	}
	
	.m-hmhot .hotopct {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		-webkit-box-pack: center;
		-webkit-justify-content: center;
		justify-content: center;
		z-index: 2;
		padding-left: 20px;
		box-sizing: border-box;
	}
	
	.m-hmhot .hotop:after,
	.m-hmhot .hotopct {
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
	}
	
	.m-hmhot .hoticon {
		width: 142px;
		height: 67px;
		background-position: -24px -30px;
	}
	
	.u-hmsprt {
		background: url(../../public/img/control.png) no-repeat;
		background-size: 166px 97px;
	}
	
	.m-hmhot .hottime {
		margin-top: 10px;
		color: hsla(0, 0%, 100%, .8);
		font-size: 12px;
		-webkit-transform: scale(.91);
		transform: scale(.91);
		-webkit-transform-origin: left top;
		transform-origin: left top;
	}
	
	.m-hmhot .hotcont {
		position: relative;
	}
	
	a,
	a:visited {
		color: #333;
		text-decoration: none;
	}
	
	.m-sgitem .sgalia {
		color: #888;
		margin-left: 4px;
	}
	
	.m-sgitem,
	.m-sgitem .sgfl {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
	}
	
	.m-sgitem {
		padding-left: 10px;
	}
	
	.m-sgitem .sgfl {
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		width: 28px;
		font-size: 17px;
		color: #999;
	}
	
	.m-sgitem,
	.m-sgitem .sgfl {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
	}
	
	.m-sgitem .sgchfl,
	.m-sgitem .sgfr {
		-webkit-box-flex: 1;
		-webkit-flex: 1 1 auto;
		flex: 1 1 auto;
	}
	
	.m-sgitem .sgfr {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		position: relative;
	}
	
	.m-sgitem .sgchfl {
		padding: 6px 0;
		width: 0;
	}
	
	.m-sgitem .sgtl {
		font-size: 17px;
	}
	
	.f-thide {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		word-break: normal;
	}
	
	.m-sgitem .sginfo {
		font-size: 12px;
		color: #888;
	}
	
	.m-sgitem .sgchply {
		display: inline-block;
		width: 22px;
		height: 22px;
		background-position: -24px 0;
	}
	
	.u-hmsprt {
		background: url(../../public/img/control.png) no-repeat;
		background-size: 166px 97px;
	}
	
	.m-hmhot .hotdn {
		height: 55px;
		line-height: 55px;
		text-align: center;
	}
	
	.m-hmhot .hotview {
		display: inline-block;
		color: #999;
		padding-right: 14px;
		background: url(../../public/img/right.svg) 100% no-repeat;
		background-size: 7px 12px;
	}
	
	.m-hmhot .hotop:after,
	.m-hmhot .hotopct {
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
	}
	
	.m-hmhot .hotop:after {
		content: " ";
		z-index: 1;
		background-color: rgba(0, 0, 0, .2);
	}
	
	.f-bd:after {
		position: absolute;
		z-index: 2;
		content: "";
		top: 0;
		left: 0;
		pointer-events: none;
		box-sizing: border-box;
		width: 100%;
		height: 100%;
		-webkit-transform-origin: top left;
		transform-origin: top left;
		border: 0 solid rgba(0, 0, 0, .1);
	}
	
	.f-bd-btm:after {
		border-bottom-width: 1px;
	}
	
	.m-sgitem .sgchfr {
		display: flex;
		align-items: center;
		padding: 0 10px;
	}
	
	.m-sgitem .cred {
		color: red;
	}
</style>